package pingan.com.imandtwo.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import chendemin.bwei.com.myapplication.gen.DaoMaster;
import chendemin.bwei.com.myapplication.gen.DaoSession;
import chendemin.bwei.com.myapplication.gen.DbBeanDao;

/**
 * Created by xsj on 2018/2/9.
 */

public class DbUtils {

    private volatile static DbUtils singleton;
    private DbUtils (){

    }
    public static DbUtils getSingleton() {
        if (singleton == null) {
            synchronized (DbUtils.class) {
                if (singleton == null) {
                    singleton = new DbUtils();
                }
            }
        }
        return singleton;
    }

    public DbBeanDao  getDbDao(Context context){
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "user", null);
// 获取数据库操作对象
        SQLiteDatabase database = helper.getWritableDatabase();
//获取DaoMaster对象
        DaoMaster daoMaster = new DaoMaster(database);
// 获取DaoSession对象
        DaoSession session = daoMaster.newSession();
// 拿到要操作的对象
        DbBeanDao dbBeanDao = session.getDbBeanDao();
        return dbBeanDao;
    }
}
